import { defineStore } from 'pinia';
import type { SysUser } from '@/api/gen-api/models/sys/SysUser.ts';

export const useAuthStore = defineStore('auth', {
  state: () => ({
    user: null as SysUser | null,
    isAdmin: false
  }),
  actions: {
    setUser(user: SysUser) {
      this.user = user;
      this.isAdmin = user.role === 'admin';
    },
    clearUser() {
      this.user = null;
      this.isAdmin = false;
    }
  },
  getters: {
    currentUserId: state => state.user?.id || null
  }
});
